import java.util.Scanner;

class ListNode{
    int val;
    ListNode next;
    ListNode(int x){
        val = x;
        next = null;
    }
}

public class Solution {
    public boolean hasCycle(ListNode head){
        ListNode fast = head;
        ListNode slow = head;

        while(fast != null && fast.next != null){
            fast = fast.next.next;
            slow = slow.next;
            if(fast == slow){
                return true;
            }
        }
        return false;
    }

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        while(in.hasNextInt()){
            int n = in.nextInt(); // 读取链表节点数量
            ListNode head = new ListNode(in.nextInt()); // 创建头节点
            ListNode tail = head;
            ListNode cycleNode = null; // 用于标记成环节点
            for(int i = 1; i < n; i++){
                ListNode node = new ListNode(in.nextInt());
                tail.next = node;
                tail = node;
                if(i == n - 2){ // 假设倒数第二个节点为成环节点
                    cycleNode = node;
                }
            }
            // 构造环
            tail.next = cycleNode;

            Solution solution = new Solution();
            boolean hasCycle = solution.hasCycle(head);
            System.out.println(hasCycle);
        }
    }
}
